const WXAPI = require('../../wxapi/main')
const CONFIG = require('../../config.js')
const app = getApp()
Page({

  /**
   * 页面的初始数据
   */
  data: {
    headerList: ['检查部位', '检查项目', '是否正常', '问题描述'],
    new_listData: [{
        "checkpart": "二维码",
        "checkitem": "李斌的检查项目",
        "isnomal": "true"
      },
      {
        "checkpart": "二维码",
        "checkitem": "李斌哥哥的检查项目",
        "isnomal": "true"
      },
      {
        "checkpart": "二维码",
        "checkitem": "李斌",
        "isnomal": "true"
      },
      {
        "checkpart": "二维码",
        "checkitem": "李斌",
        "isnomal": "true"
      },
      {
        "checkpart": "二维码",
        "checkitem": "李斌",
        "isnomal": "true"
      },
    ],
    newData: [{
      'id': 1,
      'txtpart': 'xxxx任务1',
      'txtproject': '机房服务器电源设施'
    }, {
      'id': 1,
      'txtpart': 'xxxx任务1',
      'txtproject': '机房服务器电源设施'
    }, {
      'id': 1,
      'txtpart': 'xxxx任务1',
      'txtproject': '机房服务器电源设施'
    }],
    userInfo: {},
  },

  /**
   * 生命周期函数--监听页面加载
   */    
  onLoad: function (options) {
    var _this = this;
    wx.setNavigationBarTitle({
        title: '日常安全检查',
      }),
      WXAPI.getSafeCheckList({
        id: 1
      }).then(function (res) {
        if (res.code === 200) {
          console.log('data=', res.data)
          _this.setData ({
            new_listData: res.data
          })
        }
      })
      _this.setData ({
        userInfo: wx.getStorageSync('user'),
      })
      
      console.log('user=', userInfo)

  },

  radioClick: function(e) {
    e.isnomal = !e.isnomal;
    var items = this.data.new_listData;
    for (var i = 0; i < items.length; i++){
      if (items[i].name == this.data.aa){
        for (var j = 0; j < items.length; j++) {
          // console.log("items[j].checked = ", items[j].checked);
          if (items[j].checked && j != i) {
              items[j].checked = 0;
            }
        }
        items[i].checked = !(items[i].checked);
        console.log("-----:" ,items);
        // this.setData(this.data.items[i]);
 
      }
    }
    this.setData({
      new_listData: items
    });
  },

  btn_press: function (e) {
    wx.navigateTo({
      url: '/pages/dailysafecheckdes/dailysafecheckdes',
    })
  }
})